package cz.data.domain.driver.rpc;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cz.data.common.annotation.DataInner;
import cz.data.common.base.BaseResponse;
import cz.data.common.support.db.DbProperty;
import cz.data.common.support.db.core.DbColumn;
import cz.data.common.support.db.core.DbTable;
import cz.data.common.support.db.driver.DataOperation;
import cz.data.common.support.db.driver.TableOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@FeignClient(contextId = "mongoDriverFeign", value = "mongodb-driver-api")
public interface MongoDriverFeign extends IDriverFeign {

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/connect")
    BaseResponse connect(@RequestBody DbProperty property);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/createTable")
    Boolean createTable(@RequestBody TableOperation operation);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/dropTable")
    Boolean dropTable(@RequestBody TableOperation operation);

    @Override
    @DataInner
    @GetMapping("/api/driver/mongodb/tables")
    List<DbTable> getSourceAllTable(@RequestParam("sourceId") String sourceId);

    @Override
    @DataInner
    @GetMapping("/api/driver/mongodb/columns")
    List<DbColumn> getSourceTableColumns(@RequestParam("sourceId") String sourceId,
                                         @RequestParam("tableName") String tableName);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/getDataById")
    JSONObject getDataById(@RequestBody DataOperation operation);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/getPageData")
    Page<JSONObject> getPageData(@RequestBody DataOperation operation);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/insertData")
    Boolean insertData(@RequestBody DataOperation operation);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/updateData")
    Boolean updateData(@RequestBody DataOperation operation);

    @Override
    @DataInner
    @PostMapping("/api/driver/mongodb/removeData")
    Boolean removeData(@RequestBody DataOperation operation);
}
